home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / include / x11 / region.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-11  |  4.8 KB  |  168 lines

  1. /* $XConsortium: region.h,v 11.13 91/09/10 08:21:49 rws Exp $ */
  2. /************************************************************************
  3. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  4. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its 
  9. documentation for any purpose and without fee is hereby granted, 
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in 
  12. supporting documentation, and that the names of Digital or MIT not be
  13. used in advertising or publicity pertaining to distribution of the
  14. software without specific, written prior permission.  
  15.  
  16. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  18. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. SOFTWARE.
  23.  
  24. ************************************************************************/
  25.  
  26. #ifndef _XREGION_H
  27. #define _XREGION_H
  28.  
  29. typedef struct {
  30.     short x1, x2, y1, y2;
  31. } Box, BOX, BoxRec, *BoxPtr;
  32.  
  33. typedef struct {
  34.     short x, y, width, height;
  35. }RECTANGLE, RectangleRec, *RectanglePtr;
  36.  
  37. #define TRUE 1
  38. #define FALSE 0
  39. #define MAXSHORT 32767
  40. #define MINSHORT -MAXSHORT
  41. #ifndef MAX
  42. #define MAX(a,b) (((a) > (b)) ? (a) : (b))
  43. #endif
  44. #ifndef MIN
  45. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  46. #endif
  47.  
  48.  
  49. /* 
  50.  *   clip region
  51.  */
  52.  
  53. typedef struct _XRegion {
  54.     long size;
  55.     long numRects;
  56.     BOX *rects;
  57.     BOX extents;
  58. } REGION;
  59.  
  60. /* Xutil.h contains the declaration: 
  61.  * typedef struct _XRegion *Region; 
  62.  */   
  63.  
  64. /*  1 if two BOXs overlap.
  65.  *  0 if two BOXs do not overlap.
  66.  *  Remember, x2 and y2 are not in the region 
  67.  */
  68. #define EXTENTCHECK(r1, r2) \
  69.     ((r1)->x2 > (r2)->x1 && \
  70.      (r1)->x1 < (r2)->x2 && \
  71.      (r1)->y2 > (r2)->y1 && \
  72.      (r1)->y1 < (r2)->y2)
  73.  
  74. /*
  75.  *  update region extents
  76.  */
  77. #define EXTENTS(r,idRect){\
  78.             if((r)->x1 < (idRect)->extents.x1)\
  79.               (idRect)->extents.x1 = (r)->x1;\
  80.             if((r)->y1 < (idRect)->extents.y1)\
  81.               (idRect)->extents.y1 = (r)->y1;\
  82.             if((r)->x2 > (idRect)->extents.x2)\
  83.               (idRect)->extents.x2 = (r)->x2;\
  84.             if((r)->y2 > (idRect)->extents.y2)\
  85.               (idRect)->extents.y2 = (r)->y2;\
  86.         }
  87.  
  88. /*
  89.  *   Check to see if there is enough memory in the present region.
  90.  */
  91. #define MEMCHECK(reg, rect, firstrect){\
  92.         if ((reg)->numRects >= ((reg)->size - 1)){\
  93.           (firstrect) = (BOX *) Xrealloc \
  94.           ((char *)(firstrect), (unsigned) (2 * (sizeof(BOX)) * ((reg)->size)));\
  95.           if ((firstrect) == 0)\
  96.             return(0);\
  97.           (reg)->size *= 2;\
  98.           (rect) = &(firstrect)[(reg)->numRects];\
  99.          }\
  100.        }
  101.  
  102. /*  this routine checks to see if the previous rectangle is the same
  103.  *  or subsumes the new rectangle to add.
  104.  */
  105.  
  106. #define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\
  107.                (!(((Reg)->numRects > 0)&&\
  108.                   ((R-1)->y1 == (Ry1)) &&\
  109.                   ((R-1)->y2 == (Ry2)) &&\
  110.                   ((R-1)->x1 <= (Rx1)) &&\
  111.                   ((R-1)->x2 >= (Rx2))))
  112.  
  113. /*  add a rectangle to the given Region */
  114. #define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\
  115.     if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\
  116.         CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
  117.               (r)->x1 = (rx1);\
  118.               (r)->y1 = (ry1);\
  119.               (r)->x2 = (rx2);\
  120.               (r)->y2 = (ry2);\
  121.               EXTENTS((r), (reg));\
  122.               (reg)->numRects++;\
  123.               (r)++;\
  124.             }\
  125.         }
  126.  
  127.  
  128.  
  129. /*  add a rectangle to the given Region */
  130. #define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\
  131.             if ((rx1 < rx2) && (ry1 < ry2) &&\
  132.                 CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
  133.               (r)->x1 = (rx1);\
  134.               (r)->y1 = (ry1);\
  135.               (r)->x2 = (rx2);\
  136.               (r)->y2 = (ry2);\
  137.               (reg)->numRects++;\
  138.               (r)++;\
  139.             }\
  140.         }
  141.  
  142. #define EMPTY_REGION(pReg) pReg->numRects = 0
  143.  
  144. #define REGION_NOT_EMPTY(pReg) pReg->numRects
  145.  
  146. #define INBOX(r, x, y) \
  147.       ( ( ((r).x2 >  x)) && \
  148.         ( ((r).x1 <= x)) && \
  149.         ( ((r).y2 >  y)) && \
  150.         ( ((r).y1 <= y)) )
  151.  
  152. /*
  153.  * number of points to buffer before sending them off
  154.  * to scanlines() :  Must be an even number
  155.  */
  156. #define NUMPTSTOBUFFER 200
  157.  
  158. /*
  159.  * used to allocate buffers for points and link
  160.  * the buffers together
  161.  */
  162. typedef struct _POINTBLOCK {
  163.     XPoint pts[NUMPTSTOBUFFER];
  164.     struct _POINTBLOCK *next;
  165. } POINTBLOCK;
  166.  
  167. #endif
  168.